package ntd.util.modular.function.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import ntd.util.config.common.exception.ComException;
import ntd.util.modular.function.entity.AppVersion;
import ntd.util.modular.function.mapper.AppVersionMapper;
import ntd.util.modular.function.service.AppVersionService;


import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AppVersionServiceImpl extends ServiceImpl<AppVersionMapper, AppVersion> implements AppVersionService {

    @Override
    public AppVersion getLastVersion(String appInfoId) {
        List<AppVersion> appVersions = query().eq("app_info_id", appInfoId).orderByDesc("created_date").list();
        if (CollectionUtil.isEmpty(appVersions)) {
            throw new ComException("找不到任何版本记录");
        }
        return appVersions.get(0);
    }
}
